import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        
        toolBar=QToolBar()
        toolBar.addWidget(QLabel('Orientation:'))
        cb=QComboBox()
        cb.addItems(Qt.Orientation.__members__.keys())
        cb.currentTextChanged.connect(self.OnOrientationChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('Min'))
        self.minEdit = QLineEdit()        
        toolBar.addWidget(self.minEdit)

        toolBar.addWidget(QLabel('Max'))
        self.maxEdit = QLineEdit()        
        toolBar.addWidget(self.maxEdit)

        btn =QPushButton('SetRange')
        btn.clicked.connect(self.SetRange)
        toolBar.addWidget(btn)

        layout.addWidget(toolBar)

        self.slider=QSlider()
        self.slider.valueChanged.connect(self.OnValueChanged)
        layout.addWidget(self.slider)

        self.setLayout(layout)
    def OnOrientationChanged(self,text):
        orientation=Qt.Orientation[text]
        self.slider.setOrientation(orientation)
        self.parent.OnShowMessage(f"Set Orientation:{orientation}")
    def OnValueChanged(self,value):
        self.parent.OnShowMessage(f"Current Value:{value}")
    def SetRange(self):
        min =int(self.minEdit.text())
        max =int(self.maxEdit.text())
        self.slider.setRange(min,max)
        self.parent.OnShowMessage(f'Set Range: {min}~{max}')

def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet